<?php
/**
* @package controller
* @file indexController.php
* @date 15.09.2009
* @version 1.0
* @copyright sample
* @author Harinath Reddy
* @todo phpDoc comments
*/
require_once 'Zend/Controller/Action.php';

class album_IndexController extends Cms_Controller_Action
{
	public function init()
	{
	  $this->view->siteTitle = 'Albums';
	  $this->currentPage = 1;
	  $this->resultsPerPage = 12;
			
	}
	public function indexAction()
	{
	  	
			
	}
	public function albumPersonalAction()
	{
	  	if($_SESSION["sess_userid"]!="")
		{
			$memid = $_SESSION["sess_userid"];
			$this->view->params ="";
			$result= Doctrine::getTable('AlbumCategory')->getPersonalAlbums($memid,1,12);
			//echo '<pre>';print_r($result);exit;
			$this->view->getAlbum=$result;
			$this->view->type=1;
		}
		else 
		{
			$this->_redirect("/home/");
		}
			
	}

	public function albumShareAction()
	{
	  	$memid = $_SESSION["sess_userid"];
		$this->view->params ="";
		$result= Doctrine::getTable('AlbumCategory')->getSharedAlbums($memid,1,12);
		/*foreach($result['result'] as $trigger)
		{
			//$comments[]= Doctrine::getTable('Comments')->getComments($trigger['id'],1,12);
		}*/
		//echo '<pre>';print_r($result);exit;
		$this->view->getAlbum=$result;
		$this->view->type=2;
			
	}
	
	
	public function createAlbumAction()
	{
			
			$this->_helper->layout->disableLayout();
			$type="";
			$memid = $_SESSION["sess_userid"];
			$group_type="Triggers";
			$groups = Doctrine::getTable('Groups')->getGroupsById($memid,$group_type,1);
			$events = Doctrine::getTable('EventsShared')->getEventsByUserId($memid);
			$type=$this->_getParam('type');
			if($type=="share")
			{
				$album_id=$this->_getParam('album_id');
				$groups_details = Doctrine::getTable('AlbumCategory')->getPersonalAlbumsByAlbumId($memid,$album_id);
			}
			else
			{
				$groups_details['album_id']="";
				$groups_details['title']="";
				$groups_details['description']="";
				$groups_details['eventName']="";
				$groups_details['event_id']="";
				$groups_details['visitors_allow']="";
				$groups_details['comments_allow']="";
			}
			//echo $type;exit;
			//echo '<pre>';print_r($groups_details);exit;
			$this->view->groups_details= $groups_details;
			$this->view->groups= $groups;
			$this->view->count= count($groups);
			$this->view->events= $events;
			$this->view->eventCount= count($events);
	}
	public function personalListAction()
	{
	  	
			
	}
	public function shareListAction()
	{
	  	
			
	}
	


	public function albumViewAction()
	{
			$type=base64_decode($this->_getParam('id'));
			$album_id=base64_decode($this->_getParam('current_page'));
			
			if($this->_getParam('results_per_page') != ''){
				$current_photo = $this->_getParam('results_per_page');
			} else {
				$current_photo = 1;
			}
			

			//echo $trigger_id;exit;
			$memid = $_SESSION["sess_userid"];
			//echo $memid;exit;
			$read_status= Doctrine::getTable('AlbumRelations')->updateAlbumReadStatus($memid,$album_id,1);
			$this->view->params ="";
			if($type == 3)
			{
				$view_result= Doctrine::getTable('AlbumCategory')->getSharedAlbumsByAlbumId($memid,$album_id);
			} else if($type == 2)
			{
				$view_result= Doctrine::getTable('AlbumCategory')->getPersonalAlbumsByAlbumId($memid,$album_id);
				
			} else if($type == 1)
			{
				$view_result= Doctrine::getTable('AlbumCategory')->getAllAlbumsByAlbumId($memid,$album_id);
			} else if($type == 4)
			{
				$view_result= Doctrine::getTable('AlbumCategory')->geSharetoMeAlbumsByAlbumId($memid,$album_id);
			} else if($type == 5)
			{
				$view_result= Doctrine::getTable('AlbumCategory')->gettoShareAlbumsByAlbumId($memid,$album_id);
				//echo '<pre>';print_r($result);exit;
			}
			//echo '<pre>';print_r($view_result);exit;
			$photorel_result= Doctrine::getTable('PhotoRelations')->getAlbumPhotosRelationsByAlbumId($memid,$album_id);
			//echo '<pre>';print_r($photorel_result);exit;
			if(count($photorel_result)!=0)
			{
				foreach($photorel_result as $photos)
				{
					$photo_result[]= Doctrine::getTable('Photos')->getAlbumPhotosByPhotoId($photos['photo_id']);
				}
			}
			else
			{
					//echo "chandraa";exit;
					$photo_result= Doctrine::getTable('Photos')->getAlbumPhotosByAlbumId($memid,$album_id);
			}
			//echo '<pre>';print_r($view_result);exit;
			$this->view->albumview=$view_result;
			$this->view->photoview=$photo_result;
			$this->view->addedby=$photo_result[0]['addedby'];
			$photo_id=$photo_result[0]['photo_id'];
			$comments_allow=$view_result['comments_allow'];
			$photo_description=$photo_result[0]['description'];
			$is_owner=$view_result['AlbumRelations'][0]['is_owner'];
			$photo=$photo_result[0]['photo'];
			$this->view->photo_description=$photo_description;
			$this->view->comments_allow=$comments_allow;
			$this->view->is_owner=$is_owner;
			$this->view->photo=$photo;
			$this->view->photo_id=$photo_id;
			if($photo_id==0)
			{
					$comments['currentPage']=0;
					$comments['resultsCount']=0;
					$comments['resultPerPage']=0;
					$comments['pages']=0;
					$comments['pager']=0;
					$comments['result']=Array();
			}
			else
				$comments= Doctrine::getTable('EmComments')->getComments($photo_id,1,4);
				
			$this->view->getComments=$comments;
			//echo '<pre>';print_r($comments);exit;
			//echo '<pre>';print_r(date('Y-m-d H:i:s'));exit;
			$this->view->album_id=$album_id;
			//$this->view->getComments=$comments;
			$this->view->type1=0;
			$this->view->type=$type;
			$this->view->current_photo=$current_photo;	
			
			
	}
	public function saveAction()
	{
		include('../lib/mail/SendEmail.php');
		//echo '<pre>';print_r($_POST);exit;
		
		$memid = $_SESSION["sess_userid"];
		$email = $_SESSION["sess_email"];
		$data=$_POST;
		if($_POST['event']==0 && isset($_POST['eventname'])!="")
		{
			$event_id= Doctrine::getTable('EventsShared')->addEvent($memid,$_POST['eventname']);
			$data['event']=$event_id;
		}
		//echo $data['event'];exit;
		if(isset($_POST['chkvisitor'])!='')
		{
			$data['chkvisitor']="Y";
		}
		else if(isset($_POST['chkvisitor'])=='')
		{
			$data['chkvisitor']="N";
		}
		if(isset($_POST['chkcomments'])!='')
		{
			//echo "yes";exit;
			$data['chkcomments']="Y";
		}
		else if(isset($_POST['chkcomments'])=='')
		{
			//echo "no";exit;
			$data['chkcomments']="N";
		}
		//echo '<pre>';print_r($data);exit;
		if($_POST['radio1']=="photos")
		{
			$this->sharephotos($data);
			
		}
		else
		{
				if($_POST['radio'] == "personal")
				{
					$result = Doctrine::getTable('AlbumCategory')->addAlbum($memid,$memid,$data);
				if($result)
				{
				$content_type="album";
				$share_type=1;
				$activity = Doctrine::getTable('EmActivities')->addActivity($result,$content_type,$memid,$share_type);
				}
					$is_owner=1;$group_id=0;
					$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($result,$memid,$is_owner,$group_id,$data['event']);
					//echo $r."   ".$r1;exit;
					$this->_redirect("/album/index/all");
				}
				else if($_POST['radio'] == "group")
				{
					//$result="";
					foreach($_POST['group'] as $group_id)
					{
						$result[]= Doctrine::getTable('GroupDetails')->getGroupDetailsByGroupId($group_id);
					}
					//echo '<pre>';print_r($result);exit;
					$album_id= Doctrine::getTable('AlbumCategory')->addAlbum($memid,$memid,$data);
				if($album_id)
				{
				$content_type="album";
				$share_type=2;
				$activity = Doctrine::getTable('EmActivities')->addActivity($album_id,$content_type,$memid,$share_type);
				}
					foreach($result as $r1)
					{
						foreach($r1 as $r2)
						{
							$is_owner=0;
							$res= Doctrine::getTable('AlbumRelations')->checkAlbumRelation($album_id,$r2['user_id']);
							//echo '<pre>';print_r($res);exit;
							if($res['numCount']==0)
							{
								if($r2['user_id']!=$memid)
								{
								$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$r2['user_id'],$is_owner,$r2['group_id'],$data['event']);
								//echo $r."   ".$r1;exit;
								$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($r2['user_id']);
								//echo '<pre>';print_r($notifications);exit;
								if($notifications)
								{
								if(isset($notifications[0]['uploadphoto_their'])!="off")
								{
									$loginLink = $this->CONFIG->serverAddress.'home';
									$Subject = "Album notification from EmotionsMirror";
									$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
										<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
											Emirror team';
									global $serverAddress;
									sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
								}
								}
								}
							}
						}
					}
					$this->_redirect("/album/index/all");
				}

				else if($_POST['radio']="public")
				{
						$album_id= Doctrine::getTable('AlbumCategory')->addAlbum($memid,$memid,$data);
				if($album_id)
				{
				$content_type="album";
				$share_type=3;
				$activity = Doctrine::getTable('EmActivities')->addActivity($album_id,$content_type,$memid,$share_type);
				}
						$result= Doctrine::getTable('Contacts')->getContacts($memid);
						//echo '<pre>';print_r($result);exit;
						foreach($result as $contact_id)
						{
							$is_owner=0; $group_id=0;
							$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($contact_id['contact_id']);
							//echo'<pre>';print_r($notifications['mytrigger_comments']);exit;
							$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$contact_id['contact_id'],$is_owner,$group_id,$data['event']);
							//echo $r."   ".$r1;exit;
							if($notifications)
							{
							if($notifications[0]['uploadphoto_their'] !="off")
							{
								$loginLink = $this->CONFIG->serverAddress.'home';
								$Subject = "Album notification from EmotionsMirror";
								$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
									<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
										Emirror team';
								global $serverAddress;
								sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
							}
							}
							
							$r1[]= Doctrine::getTable('Contacts')->getFriendsContacts($contact_id['contact_id'],$memid);
							
						}
						//echo '<pre>';print_r($r1);exit;
						foreach($r1 as $r1)
						{
							foreach($r1 as $r2)
							{
								if($r2['contact_id']!=" " && $r2['contact_id']!=$memid)
								{
									$is_owner=0; $group_id=0;
									$result= Doctrine::getTable('AlbumRelations')->checkAlbumRelation($album_id,$r2['contact_id']);
									//echo '<pre>';print_r();exit;
									if($result['numCount']==0)
									{
										$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$r2['contact_id'],$is_owner,$group_id=0,$data['event']);
										//echo $r."   ".$r1;exit;
									}
									$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($r2['contact_id']);
									if($notifications)
									{
									if($notifications[0]['uploadphoto_their'] !="off")
									{
										$loginLink = $this->CONFIG->serverAddress.'home';
										$Subject = "Album notification from EmotionsMirror";
										$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
											<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
												Emirror team';
										global $serverAddress;
										sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
									}
									}
									
								}
							}
						}
					$this->_redirect("/album/index/all");	
			}
		}	
	}
	public function sharephotos($data)
	{	
				$memid = $_SESSION["sess_userid"];
				//echo '<pre>';print_r($data);exit;
				$timediffId = time();
				if($_POST['radio'] == "personal")
				{	
					foreach($data['fileNames'] as $photo)
					{
						//echo $photo;exit;
						$type="P";$album_id=0;
						$result = Doctrine::getTable('Photos')->addPhoto($memid,$type,$album_id,$photo,$timediffId,$data['chkcomments']);
						$is_owner=1;$group_id=0;
						$r= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$result,$memid,$is_owner,$group_id,$data['event'],$timediffId);
						//echo $r."   ".$r1;exit;
					}
						if($result)
						{
						$content_type="photos";
						$share_type=1;
						$activity = Doctrine::getTable('EmActivities')->addActivity($result,$content_type,$memid,$share_type);
						}
					$this->_redirect("/album/photos/all");
				}
						
				else if($_POST['radio'] == "group")
				{
					//$result="";
					foreach($_POST['group'] as $group_id)
					{
						$result[]= Doctrine::getTable('GroupDetails')->getGroupDetailsByGroupId($group_id);
					}
					//echo '<pre>';print_r($result);exit;
				foreach($data['fileNames'] as $photo)
				{
						$type="P";$album_id=0;
						$photo_id = Doctrine::getTable('Photos')->addPhoto($memid,$type,$album_id,$photo,$timediffId,$data['chkcomments']);
						$r= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$memid,1,0,$data['event'],$timediffId);
						$is_owner=0;
					foreach($result as $r1)
					{
						foreach($r1 as $r2)
						{
							$is_owner=0;$album_id=0;
							$res= Doctrine::getTable('PhotoRelations')->checkPhotoRelation($photo_id,$r2['user_id']);
							//echo '<pre>';print_r($res);exit;
							if($res['numCount']==0)
							{
							$r= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$r2['user_id'],$is_owner,$r2['group_id'],$data['event'],$timediffId);
							//echo $r."   ".$r1;exit;
							$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($r2['user_id']);
								if($notifications)
								{
								if(isset($notifications[0]['uploadphoto_their'])!="off")
								{
									$loginLink = $this->CONFIG->serverAddress.'home';
									$Subject = "Album notification from EmotionsMirror";
									$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
										<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
											Emirror team';
									global $serverAddress;
									sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
								}
								}
							}
						}
					}
				}
						if($photo_id)
						{
						$content_type="photos";
						$share_type=2;
						$activity = Doctrine::getTable('EmActivities')->addActivity($photo_id,$content_type,$memid,$share_type);
						}
					$this->_redirect("/album/photos/all");
			}

				else if($_POST['radio']="public")
				{
					foreach($data['fileNames'] as $photo)
					{
						$type="P";$album_id=0;
						$photo_id = Doctrine::getTable('Photos')->addPhoto($memid,$type,$album_id,$photo,$timediffId,$data['chkcomments']);
						$r= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$memid,1,0,$data['event'],$timediffId);
						$is_owner=0;
						$result= Doctrine::getTable('Contacts')->getContacts($memid);
						//echo '<pre>';print_r($result);exit;
						foreach($result as $contact_id)
						{
							$is_owner=0; $group_id=0;
							$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($contact_id['contact_id']);
							//echo'<pre>';print_r($notifications['mytrigger_comments']);exit;
							$r= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$contact_id['contact_id'],$is_owner,$group_id,$data['event'],$timediffId);
							//echo $r."   ".$r1;exit;
							if($notifications)
							{
							if($notifications[0]['uploadphoto_their'] !="off")
							{
								$loginLink = $this->CONFIG->serverAddress.'home';
								$Subject = "Album notification from EmotionsMirror";
								$Message = 'Hello "'.$contact_id['first_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
									<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
										Emirror team';
								global $serverAddress;
								sendMail($contact_id['contact_email'],$Subject,$Message,$_SESSION["sess_email"]);
							}
							}
							$r1[]= Doctrine::getTable('Contacts')->getFriendsContacts($contact_id['contact_id'],$memid);
							//echo '<pre>';print_r($r1);exit;
						}
						//echo '<pre>';print_r($r1);exit;
						foreach($r1 as $r1)
						{
							foreach($r1 as $r2)
							{
								if($r2['contact_id']!=" " && $r2['contact_id']!=$memid)
								{
									$is_owner=0; $group_id=0;
									$result= Doctrine::getTable('PhotoRelations')->checkPhotoRelation($photo_id,$r2['contact_id']);
									//echo '<pre>';print_r();exit;
									if($result['numCount']==0)
									{
										$r= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$r2['contact_id'],$is_owner,$group_id=0,$data['event']);
										//echo $r."   ".$r1;exit;
									}
									$notifications = Doctrine::getTable('Notifications')->getNotifications($r2['contact_id']);
									if($notifications)
									{
									if($notifications[0]['uploadphoto_their'] !="off")
									{
										$loginLink = $this->CONFIG->serverAddress.'home';
										$Subject = "Trigger notification from EmotionsMirror";
										$Message = 'Hello "'.$r2['first_name'].'",<br/><br/>you have TriggerNotification  in your emotionmirror  <br/><br/>
											<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
												Emirror team';
										global $serverAddress;
										sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
									}
									}
								}
							}
						}
					}
						if($photo_id)
						{
						$content_type="photos";
						$share_type=3;
						$activity = Doctrine::getTable('EmActivities')->addActivity($photo_id,$content_type,$memid,$share_type);
						}
					$this->_redirect("/album/photos/all");	
			}
	}
	public function shareAction()
	{
		include('../lib/mail/SendEmail.php');
		//echo '<pre>';print_r($_POST);exit;
		$album_id=$this->_getParam('id');
		$memid = $_SESSION["sess_userid"];
		$email = $_SESSION["sess_email"];
		$data=$_POST;
		if(isset($_POST['chkvisitor'])!='')
		{
			$data['chkvisitor']="Y";
		}
		else if(isset($_POST['chkvisitor'])=='')
		{
			$data['chkvisitor']="N";
		}
		if(isset($_POST['chkcomments'])!='')
		{
			$data['chkcomments']="Y";
		}
		else if(isset($_POST['chkcomments'])=='')
		{
			$data['chkcomments']="N";
		}
		//echo '<pre>';print_r($data);exit;
		$update_result= Doctrine::getTable('AlbumCategory')->updateAlbumCategoryTable($album_id,$data);
		$dlete_result= Doctrine::getTable('AlbumRelations')->deletepersonalAlbumInRelations($album_id,$memid);
		 if($_POST['radio'] == "group")
		{
			//$result="";
			foreach($_POST['group'] as $group_id)
			{
				$result[]= Doctrine::getTable('GroupDetails')->getGroupDetailsByGroupId($group_id);
			}
			//echo '<pre>';print_r($result);exit;
			foreach($result as $r1)
			{
				foreach($r1 as $r2)
				{
					$is_owner=0;
					$res= Doctrine::getTable('AlbumRelations')->checkAlbumRelation($album_id,$r2['user_id']);
					//echo '<pre>';print_r($res);exit;
					if($res['numCount']==0)
					{
					$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$r2['user_id'],$is_owner,$r2['group_id'],$data['event']);
					//echo $r."   ".$r1;exit;
					$loginLink = $this->CONFIG->serverAddress.'home';
					$Subject = "Album notification from EmotionsMirror";
					$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
						<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
							Emirror team';
					global $serverAddress;
					sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
					}
				}
			}
			$this->_redirect("/album/index/all");
		}

		else if($_POST['radio']="public")
		{
				$result= Doctrine::getTable('Contacts')->getContacts($memid);
				//echo '<pre>';print_r($result);exit;
				foreach($result as $contact_id)
				{
					$is_owner=0; $group_id=0;
					//$notifications = Doctrine::getTable('Notifications')->getNotifications($contact_id['contact_id']);
					//echo'<pre>';print_r($notifications['mytrigger_comments']);exit;
					$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$contact_id['contact_id'],$is_owner,$group_id,$data['event']);
					//echo $r."   ".$r1;exit;
					//if($notifications['others_shared_triggers'] !="off")
					
					$loginLink = $this->CONFIG->serverAddress.'home';
					$Subject = "Album notification from EmotionsMirror";
					$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
						<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
							Emirror team';
					global $serverAddress;
					sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
					
					$r1[]= Doctrine::getTable('Contacts')->getFriendsContacts($contact_id['contact_id'],$memid);
					
				}
				//echo '<pre>';print_r($r1);exit;
				foreach($r1 as $r1)
				{
					foreach($r1 as $r2)
					{
						if($r2['contact_id']!=" ")
						{
							$is_owner=0; $group_id=0;
							$result= Doctrine::getTable('AlbumRelations')->checkAlbumRelation($album_id,$r2['contact_id']);
							//echo '<pre>';print_r();exit;
							if($result['numCount']==0)
							{
								$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$r2['contact_id'],$is_owner,$group_id=0,$data['event']);
								//echo $r."   ".$r1;exit;
							}
							//$notifications = Doctrine::getTable('Notifications')->getNotifications($r2['contact_id']);
							//if($notifications['others_shared_triggers'] !="off")
							
							$loginLink = $this->CONFIG->serverAddress.'home';
							$Subject = "Trigger notification from EmotionsMirror";
							$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have TriggerNotification  in your emotionmirror  <br/><br/>
								<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
									Emirror team';
							global $serverAddress;
							sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
							
						}
					}
				}
			$this->_redirect("/album/index/all");	
		}
			
	}
	public function deleteAlbumAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$memid=$_SESSION["sess_userid"];
	  	$album_id = $_POST['val'];
		$status="Inactive";
		$result = Doctrine::getTable('AlbumRelations')->deleteAlbum($album_id,$memid,$status);
		$jsonData['output'] = $result;
		$this->_helper->json->sendJson($jsonData);	
	}
	public function favoriteAction()
	{
		//echo '<pre>';print_r($_POST);exit;
	  	$memid = $_SESSION["sess_userid"];
		$album_id=$_POST["album_id"];
		$status=$_POST["status"];
		$type=$_POST["type"];
		if($status=="Active")
		{
		 //trig $status;exit;
		$result= Doctrine::getTable('MyFavorites')->addToFavorite($memid,$album_id,$type);
		//echo '<pre>';print_r($result);exit;
		}
		else
		{
			if($status=="Inactive")
			{
				//echo "inactive";exit;
				$result= Doctrine::getTable('MyFavorites')->inactiveFavorite($memid,$album_id,$type);
				//echo '<pre>';print_r($result);exit;
			}
		}
		$jsonData['output'] = $result;
		$this->_helper->json->sendJson($jsonData);
			
	}
	public function deletesharedAlbumAction()
	{
		//echo '<pre>';print_r($_POST);exit;
	  	$memid = $_SESSION["sess_userid"];
		$id = $_POST["val"];
		$action = $_POST["action"];
		//echo $id."  and  ".$action;exit;
		if($action == "album_id")
		{
		$result= Doctrine::getTable('AlbumRelations')->deleteAlbumByAlbumId($id);
		}
		else
		{		
			if($action == "relation_id")
			{
			$result= Doctrine::getTable('AlbumRelations')->deleteAlbumByRelationId($id);
			//echo $result;exit;
			}
		}
		//echo '<pre>';print_r($result);exit;
		$jsonData['output'] = $result;
		$this->_helper->json->sendJson($jsonData);
			
	}
	public function statsAllPracticeAction()
	{	
		//echo '<pre>';print_r($_POST);exit;
		$memid = $_SESSION["sess_userid"];
		$filtr = $_POST['filter'];
		if($filtr==2)
		{
		//echo "dsd\f";exit;
			$this->view->params ="";
			$result= Doctrine::getTable('AlbumCategory')->getPersonalAlbums($memid,1,1);
			//echo '<pre>';print_r($result);exit;
			$this->view->getAlbum=$result;
			$this->view->type=1;
		$jsonData['output'] = $this->view->render('index/personal-list.html');
		}
		if($filtr==3)
		{
			//echo "dsd\f";exit;
			$this->view->params ="";
			$result= Doctrine::getTable('AlbumCategory')->getSharedAlbums($memid,1,12);
			//echo '<pre>';print_r($result);exit;
			$this->view->getAlbum=$result;
			$this->view->type=2;
		$jsonData['output'] = $this->view->render('index/share-list.html');
		}
		$this->_helper->json->sendJson($jsonData);
	}
	public function updateAlbumTitleAction()
	{
		$memid = $_SESSION["sess_userid"];
		//echo '<pre>';print_r($_POST);exit;
		if(isset($_POST['chkvisitor'])== "on")
		{
			$_POST['chkvisitor']="Y";
		}
		else
		{
			$_POST['chkvisitor']="N";
		}
		if(isset($_POST['chkcomments'])== "on")
		{
			$_POST['chkcomments']="Y";
		}
		else
		{
			$_POST['chkcomments']="N";
		}
		if($_POST['event']==0 && isset($_POST['eventname'])!="")
		{
			$event_id= Doctrine::getTable('EventsShared')->addEvent($memid,$_POST['eventname']);
			$_POST['event']=$event_id;
		}
		//echo $_POST['event'];exit;
		$album_id=base64_decode($this->_getParam('id'));
		$type=base64_decode($this->_getParam('current_page'));
		//echo $type;exit;
		$result= Doctrine::getTable('AlbumCategory')->updateAlbumDetailsByAlbumId($album_id,$_POST);
		$result1= Doctrine::getTable('AlbumRelations')->updateAlbumEventIdByAlbumId($album_id,$_POST);
		//echo $result;exit;
		$this->_redirect("/album/index/album-view/".base64_encode($type)."/".base64_encode($album_id));
	}
	public function editAlbumTitleAction()
	{
		$this->_helper->layout->disableLayout();
		$memid = $_SESSION["sess_userid"];
		$album_id=base64_decode($this->_getParam('album_id'));
		$type=base64_decode($this->_getParam('type'));
		//echo $album_id;exit;
		$result= Doctrine::getTable('AlbumCategory')->getAlbumDetailsByAlbumId($album_id);
		$group_type="Triggers";
		$groups = Doctrine::getTable('Groups')->getGroupsById($memid,$group_type,1);
		$events = Doctrine::getTable('EventsShared')->getEventsByUserId($memid);
		//echo '<pre>';print_r($result);exit;
		$this->view->Album=$result;
		$this->view->album_id=$album_id;
		$this->view->type=$type;
		$this->view->groups= $groups;
		$this->view->count= count($groups);
		$this->view->events= $events;
		$this->view->eventCount= count($events);

	}
	public function allAction()
	{
		//echo 'sfsd';exit;
	  	if(!isset($_POST['filter']))
		{
			//echo '<pre>';print_r($_POST);exit;
			//echo 'sdfsdf';exit;
			$memid = $_SESSION["sess_userid"];
			$this->view->params ="";
			$result= Doctrine::getTable('AlbumCategory')->getAllAlbums($memid,$this->currentPage,$this->resultsPerPage);
			//echo '<pre>';print_r($result);exit;
			$this->view->getAlbum=$result;
			$this->view->type=1;
		} else {
			//echo '<pre>';print_r($_POST);exit;
			$filtr = $_POST['filter'];
			if(isset($_POST['search_key']) && $_POST['search_key']!='')
			{
				$serValue = $_POST['search_key'];
			} else {
				$serValue = '';
			}
			$memid = $_SESSION["sess_userid"];
			//echo $filtr;exit;
			if($filtr == 3)
			{
				$result= Doctrine::getTable('AlbumCategory')->getSharedAlbums($memid,$this->currentPage,$this->resultsPerPage,$serValue);
			} else if($filtr == 2)
			{
				$result= Doctrine::getTable('AlbumCategory')->getPersonalAlbums($memid,$this->currentPage,$this->resultsPerPage,$serValue);
				
			} else if($filtr == 1)
			{
				$result= Doctrine::getTable('AlbumCategory')->getAllAlbums($memid,$this->currentPage,$this->resultsPerPage,$serValue);
			} else if($filtr == 4)
			{
				$result= Doctrine::getTable('AlbumCategory')->geSharetoMeAlbums($memid,$this->currentPage,$this->resultsPerPage,$serValue);
			} else if($filtr == 5)
			{
				$result= Doctrine::getTable('AlbumCategory')->gettoShareAlbums($memid,$this->currentPage,$this->resultsPerPage,$serValue);
				//echo '<pre>';print_r($result);exit;
			}
			//echo '<pre>';print_r($result);exit;
			$this->view->getAlbum=$result;
			$this->view->type=$filtr;
			$this->view->params ="";
			$jsonData['output'] = $result;
			$jsonData['pages'] = $result ['pages'];
			$jsonData['pager'] = $result ['pager'];
			$jsonData['currentPage'] = $result ['currentPage'];
			$jsonData['resultsCount'] = $result ['resultsCount'];
			if($filtr == 1)
			{
				$jsonData['output'] = $this->view->render('index/share-list.html');
				$this->_helper->json->sendJson($jsonData);	
				
			} else if($filtr == 2)
			{
				$jsonData['output'] = $this->view->render('index/share-list.html');
				$this->_helper->json->sendJson($jsonData);	
				
			} else if($filtr == 3) {
				$jsonData['output'] = $this->view->render('index/share-list.html');
				$this->_helper->json->sendJson($jsonData);			
			} else if($filtr == 4)
			{
				$jsonData['output'] = $this->view->render('index/share-list.html');
				$this->_helper->json->sendJson($jsonData);	
				
			} else if($filtr == 5)
			{
				$jsonData['output'] = $this->view->render('index/share-list.html');
				$this->_helper->json->sendJson($jsonData);	
				
			}			
		
		}
		
			
	}
	public function paginationAction()
	{
		$type=$this->_getParam('id');
		//echo $type;exit;
		$memid=$_SESSION["sess_userid"];
		$this->view->params ="";
		$this->view->type=$type;
		$currentPage = $this->_getParam('current_page') == 0? 1:$this->_getParam('current_page');
		$resultsPerPage = $this->_getParam('results_per_page') == 0? 12:$this->_getParam('results_per_page');
		$serValue = $this->_getParam('orderby') == ''? '':$this->_getParam('orderby');
		if($serValue==0)
		{
			$serValue='';
		}
		//echo $serValue;exit;
		if($type == 1)
		{
		$ideaDetails = Doctrine::getTable('AlbumCategory')->getAllAlbums($memid,$currentPage,$resultsPerPage,$serValue);
		$this->view->getAlbum = $ideaDetails;
		//echo '<pre>';print_r($ideaDetails);exit;
					$this->view->addedby=$ideaDetails['result'][0]['added_by'];
			$this->view->comments_allow=$ideaDetails['result'][0]['comments_allow'];
		$jsonData['output'] = $this->view->render('index/share-list.html');
		}
		else if($type == 2)
		{
			$ideaDetails= Doctrine::getTable('AlbumCategory')->getPersonalAlbums($memid,$currentPage,$resultsPerPage,$serValue);
			$this->view->getAlbum = $ideaDetails;
						$this->view->addedby=$ideaDetails['result'][0]['added_by'];
			$this->view->comments_allow=$ideaDetails['result'][0]['comments_allow'];
			$jsonData['output'] = $this->view->render('index/share-list.html');
		}
		else if($type == 3)
		{
			$ideaDetails= Doctrine::getTable('AlbumCategory')->getSharedAlbums($memid,$currentPage,$resultsPerPage,$serValue);
			$this->view->getAlbum = $ideaDetails;
						$this->view->addedby=$ideaDetails['result'][0]['added_by'];
			$this->view->comments_allow=$ideaDetails['result'][0]['comments_allow'];
			$jsonData['output'] = $this->view->render('index/share-list.html');
		}
		else if($type == 4)
		{
			$ideaDetails= Doctrine::getTable('AlbumCategory')->geSharetoMeAlbums($memid,$currentPage,$resultsPerPage,$serValue);
			$this->view->getAlbum = $ideaDetails;
						$this->view->addedby=$ideaDetails['result'][0]['added_by'];
			$this->view->comments_allow=$ideaDetails['result'][0]['comments_allow'];
			$jsonData['output'] = $this->view->render('index/share-list.html');
		}
		else if($type == 5)
		{
			$ideaDetails= Doctrine::getTable('AlbumCategory')->gettoShareAlbums($memid,$currentPage,$resultsPerPage,$serValue);
			//echo '<pre>';print_r($ideaDetails);exit;
			$this->view->getAlbum = $ideaDetails;
			$this->view->addedby=$ideaDetails['result'][0]['added_by'];
			$this->view->comments_allow=$ideaDetails['result'][0]['comments_allow'];
			$jsonData['output'] = $this->view->render('index/share-list.html');
		}
		else
		{
			//echo "fdfbjfjsbk";exit;
			$photo_id=$type;
			$is_owner=0;
			$ideaDetails= Doctrine::getTable('EmComments')->getComments($photo_id,$currentPage,$resultsPerPage);
			 
			$this->view->getComments = $ideaDetails;
			$result= Doctrine::getTable('Photos')->getAlbumPhotosByPhotoId($photo_id);
			//echo '<pre>';print_r($result);exit;
			$this->view->photo_id=$photo_id;
			if($result['album_id']!=0)
			{
				$result_value= Doctrine::getTable('AlbumRelations')->getIsOwner($result['album_id'],$memid);
				$is_owner=$result_value['is_owner'];
			}
			$this->view->is_owner=$is_owner;
			$this->view->photo_description=$result['description'];
			$this->view->addedby=$result['addedby'];
			$this->view->comments_allow=$result['comments_allow'];
			$jsonData['output'] = $this->view->render('index/photo-comments.html');
		}
		//echo '<pre>';print_r($ideaDetails);exit;
		//$this->view->type=$type;
		
		$jsonData['pages'] = $ideaDetails['pages'];
	    $jsonData['pager'] = $ideaDetails['pager'];
	    $jsonData['currentPage'] = $ideaDetails['currentPage'];
		$jsonData['resultsCount'] = $ideaDetails['resultsCount'];
		
		$this->_helper->json->sendJson($jsonData);
		//echo '<pre>';print_r($ideaDetails);exit;
		
	
	}

	public function addPhotosAction()
	{
		$this->_helper->layout->disableLayout();
		$album_id=base64_decode($this->_getParam('album_id'));
		$type=base64_decode($this->_getParam('type'));
		$this->view->album_id=$album_id;
		$this->view->type=$type;
	}
		public function sharePhotoAction()
	{
		$this->_helper->layout->disableLayout();
		$memid = $_SESSION["sess_userid"];
		$photo_id=$this->_getParam('photo_id');
		$album_id=$this->_getParam('album_id');
		$group_type="triggers";
		$events = Doctrine::getTable('EventsShared')->getEventsByUserId($memid);
		$groups_details = Doctrine::getTable('AlbumCategory')->getPersonalAlbumsByAlbumId($memid,$album_id);
		//echo '<pre>';print_r($groups_details);exit;
		$groups = Doctrine::getTable('Groups')->getGroupsById($memid,$group_type,1);
		$this->view->groups=$groups;
		$this->view->groups_details=$groups_details;
		$this->view->events=$events;
		$this->view->count= count($groups);
		$this->view->album_id=$album_id;
		$this->view->photo_id=$photo_id;
	}
	public function uploadPhotosAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$memid = $_SESSION["sess_userid"];
		$this->_helper->layout->disableLayout();
		$album_id=base64_decode($this->_getParam('id'));
		$type=base64_decode($this->_getParam('current_page'));
		$org_type="P";
		//echo $album_id;exit;
		//echo '<pre>';print_r($result['member_id']);
		//echo $memid;exit;
		foreach($_POST['fileNames'] as $filenames)
		{
		//echo $filenames;exit;
		$result= Doctrine::getTable('Photos')->addAlbumPhotos($album_id,$filenames,$org_type,$memid);
		}
		$result= Doctrine::getTable('AlbumCategory')->getAlbumOwner($album_id);
		if($result['member_id']!=$memid)
		{
			$notifications = Doctrine::getTable('AlbumNotifications')->getNotifications($result['member_id']);
			if($notifications)
			{
			if(isset($notifications[0]['uploadphoto_shared'])!="off")
			{
					$user_name = Doctrine::getTable('Users')->getEmail($result['member_id']);
					$loginLink = $this->CONFIG->serverAddress.'home';
					$Subject = "Album photos notification from EmotionsMirror";
					$Message = 'Hello "'.$user_name['user_name'].'",<br/><br/>This person added some photos to your album<br/><br/>
						<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
							Emirror team';
					global $serverAddress;
					sendMail($user_name['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
			}
			}
		}
		$this->_redirect("/album/index/album-view/".base64_encode($type)."/".base64_encode($album_id));
	}
	public function uploadImagesAction()
	  {
	   //echo "uploading";exit;
		  $this->_helper->layout->disableLayout();
		  $this->getHelper('viewRenderer')->setNoRender();
		  $imagesDir = '../'.$this->CONFIG->path->albumPhotosBig;
		  $imagesThumbDir = '../'.$this->CONFIG->path->albumPhotosThumb;
		if(isset($_FILES['vfile']))
		  {
			 $size=$_FILES['vfile']['size'];
			 //echo $_FILES['vfile']['name'];exit;
		   	 $name = time().'_-_'.$_FILES['vfile']['name'];
			//echo $name;exit;
		 	echo $vidfile = $this->uploadFile($_FILES['vfile']['tmp_name'],$imagesDir,$imagesThumbDir,$name);
		}
	}
		public function uploadFile($tnm,$path,$path1,$fnm)
	 {
	 //echo "hi from  upload file method";
		   $fnm = str_replace(' ','_',$fnm);
		  if(move_uploaded_file($tnm,$path.$fnm))
		    {
			//echo "hi from  upload file method";exit;
			   createthumb($path.$fnm, $path1.$fnm, "150", "150");
			   return $fnm;
		    }
		 else
			return "";
     }
	 public function removeAction()
	{
		$this->_helper->layout->disableLayout();
		//$videosTemp= '../'.$this->CONFIG->path->contentTempFiles;
		  $imagesDir = '../'.$this->CONFIG->path->albumPhotosBig;
		  $imagesThumbDir = '../'.$this->CONFIG->path->albumPhotosThumb;
		$videoFile = trim($_GET['filename']);
		@unlink($imagesDir.$videoFile);
		@unlink($imagesThumbDir.$videoFile);
		$jsonData['rows']  = 0;
		$this->_helper->json->sendJson($jsonData);

	}	
	public function submitCommentAction()
	{	
		//echo '<pre>';print_r($_POST);exit;
		$memid = $_SESSION["sess_userid"];
			$result= Doctrine::getTable('EmComments')->addComments($memid,$_POST);
			$jsonData['output'] = 1;
			$this->_helper->json->sendJson($jsonData);
	}
	public function showCommentsAction()
	{	
		//echo '<pre>';print_r($_POST);exit;
		$memid = $_SESSION["sess_userid"];
		$is_owner=0;
			$comments= Doctrine::getTable('EmComments')->getComments($_POST['photo_id'],1,4);
			
			$result= Doctrine::getTable('Photos')->getAlbumPhotosByPhotoId($_POST['photo_id']);
			//echo '<pre>';print_r($result);exit;
			if($result['album_id']!=0)
			{
				$result_value= Doctrine::getTable('AlbumRelations')->getIsOwner($result['album_id']);
				$is_owner=$result_value['is_owner'];
				$comments_allow=$result_value['comments_allow'];
				//echo '<pre>';print_r($result_value);exit;
				$result['AlbumRelations'][0]['is_owner']=$is_owner;
				$this->view->photo_id=$_POST['photo_id'];
				$this->view->comments_allow=$comments_allow;
				$this->view->albumview=$result;
				$this->view->photo=$result['photo'];
				$jsonData['output1'] = $this->view->render('index/bar.html');
			}
			else
			{
				$comments_allow=$result['comments_allow'];
				$this->view->photo_id=$_POST['photo_id'];
				$this->view->photo=$result['photo'];
				$this->view->comments_allow=$comments_allow;
				$this->view->added_date=$result['added_date'];
				$this->view->photo_diffid=$result['photo_diffid'];
				$jsonData['output1'] = $this->view->render('photos/photo-bar.html');
				
			}
			//echo '<pre>';print_r($result);exit;
			$this->view->is_owner=$is_owner;
			$this->view->getComments=$comments;
			//echo $_POST['photo_id'];exit;
			$this->view->photo_id=$_POST['photo_id'];
			$this->view->photo_description=$result['description'];
			$this->view->addedby=$result['addedby'];
			$this->view->photo=$result['photo'];
			$this->view->params = '';
			//$this->view->albumview['album_id']=$result['album_id'];
			//$this->view->albumview['AlbumRelations'][0]['is_owner']=$is_owner;
			$jsonData['output'] = $this->view->render('index/photo-comments.html');
			$this->_helper->json->sendJson($jsonData);
	}
	public function commentsPaginationAction()
	{	
		$memid=$_SESSION["sess_userid"];
		$this->view->params ="";
		$photoId=$this->_getParam('id');
		$currentPage = $this->_getParam('current_page') == 0? 1:$this->_getParam('current_page');
		$resultsPerPage = $this->_getParam('results_per_page') == 0? 12:$this->_getParam('results_per_page');
		$serValue = $this->_getParam('orderby') == ''? '':$this->_getParam('orderby');
		
		$comments= Doctrine::getTable('EmComments')->getComments($photoId,$currentPage,$resultsPerPage);
		//$result= Doctrine::getTable('Photos')->getAlbumPhotosByPhotoId($photoId);
		//echo '<pre>';print_r($result['description']);exit;
		$this->view->getComments=$comments;
		$this->view->photo_id= $photoId;
		$this->view->photo_description='STATIC DESC';
		$jsonData['output'] = $this->view->render('index/photo-comments.html');
		$this->_helper->json->sendJson($jsonData);
	}
	public function sendNotficaation()
	{
	
	}
	public function deleteCommentAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$memid=$_SESSION["sess_userid"];
	  	$comment_id = $_POST['comment_id'];
		$album_id = $_POST['album_id'];
		$type = $_POST['type'];
		$photo_id=$_POST['photo_id'];
		$currentPage=$_POST['current_page'];
		$result = Doctrine::getTable('EmComments')->deleteComment($comment_id);
		$jsonData =1;
		$this->_helper->json->sendJson($jsonData);	
	}
	public function deletePhotoAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$memid=$_SESSION["sess_userid"];
	  	$photo_id=$_POST['photo_id'];
		$result= Doctrine::getTable('Photos')->deletePhotoByPhotoId($photo_id);
		//echo $result;exit;
		$jsonData['output'] = $result;
		$this->_helper->json->sendJson($jsonData);	
	}
	public function addDescriptionAction()
	{
		//echo '<pre>';print_r($_POST);exit;
		$memid=$_SESSION["sess_userid"];
	  	$photo_id = $_POST['photo_id'];
		$description = $_POST['description'];
		$is_owner = $_POST['is_owner'];
		$result = Doctrine::getTable('Photos')->addDescription($photo_id,$description);
		$jsonData['output'] = 1;
		$this->_helper->json->sendJson($jsonData);	
	}
	public function photoShareAction()
	{
		include('../lib/mail/SendEmail.php');
		//echo '<pre>';print_r($_POST);exit;
		$album_id=base64_decode($this->_getParam('id'));
		$photo_id=base64_decode($this->_getParam('current_page'));
		$memid = $_SESSION["sess_userid"];
		$email = $_SESSION["sess_email"];
		$data=$_POST;
		//echo '<pre>';print_r($data);exit;
		$delete_result= Doctrine::getTable('AlbumRelations')->deletepersonalAlbumInRelations($album_id,$memid);
		 if($_POST['radio'] == "group")
		{
			//$result="";
			foreach($_POST['group'] as $group_id)
			{
				$result[]= Doctrine::getTable('GroupDetails')->getGroupDetailsByGroupId($group_id);
			}
			//echo '<pre>';print_r($result);exit;
			foreach($result as $r1)
			{
				foreach($r1 as $r2)
				{
					$is_owner=0;
					$res= Doctrine::getTable('AlbumRelations')->checkAlbumRelation($album_id,$r2['user_id']);
					//echo '<pre>';print_r($res);exit;
					if($res['numCount']==0)
					{
					$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$r2['user_id'],$is_owner,$r2['group_id'],$data['event']);
					$photo_relation= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$r2['user_id'],$is_owner,$r2['group_id'],$data['event']);
					//echo $r."   ".$r1;exit;
					$loginLink = $this->CONFIG->serverAddress.'home';
					$Subject = "Album notification from EmotionsMirror";
					$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
						<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
							Emirror team';
					global $serverAddress;
					sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
					}
				}
			}
			$this->_redirect("/album/index/all");
		}

		else if($_POST['radio']="public")
		{
				$result= Doctrine::getTable('Contacts')->getContacts($memid);
				//echo '<pre>';print_r($result);exit;
				foreach($result as $contact_id)
				{
					$is_owner=0; $group_id=0;
					//$notifications = Doctrine::getTable('Notifications')->getNotifications($contact_id['contact_id']);
					//echo'<pre>';print_r($notifications['mytrigger_comments']);exit;
					$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$contact_id['contact_id'],$is_owner,$group_id,$data['event']);
					$photo_relation= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$contact_id['contact_id'],$is_owner,$group_id,$data['event']);
					//echo $r."   ".$r1;exit;
					//if($notifications['others_shared_triggers'] !="off")
					
					$loginLink = $this->CONFIG->serverAddress.'home';
					$Subject = "Album notification from EmotionsMirror";
					$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have AlbumNotification  in your emotionmirror  <br/><br/>
						<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
							Emirror team';
					global $serverAddress;
					sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
					
					$r1[]= Doctrine::getTable('Contacts')->getFriendsContacts($contact_id['contact_id'],$memid);
					
				}
				//echo '<pre>';print_r($r1);exit;
				foreach($r1 as $r1)
				{
					foreach($r1 as $r2)
					{
						if($r2['contact_id']!=" ")
						{
							$is_owner=0; $group_id=0;
							$result= Doctrine::getTable('AlbumRelations')->checkAlbumRelation($album_id,$r2['contact_id']);
							//echo '<pre>';print_r();exit;
							if($result['numCount']==0)
							{
								$r= Doctrine::getTable('AlbumRelations')->addAlbumRelation($album_id,$r2['contact_id'],$is_owner,$group_id=0,$data['event']);
								$photo_relation= Doctrine::getTable('PhotoRelations')->addPhotoRelation($album_id,$photo_id,$r2['contact_id'],$is_owner,$group_id=0,$data['event']);

								//echo $r."   ".$r1;exit;
							}
							//$notifications = Doctrine::getTable('Notifications')->getNotifications($r2['contact_id']);
							//if($notifications['others_shared_triggers'] !="off")
							
							$loginLink = $this->CONFIG->serverAddress.'home';
							$Subject = "Trigger notification from EmotionsMirror";
							$Message = 'Hello "'.$r2['user_name'].'",<br/><br/>you have TriggerNotification  in your emotionmirror  <br/><br/>
								<br/><br/><br/>Please click on the following link to login into emirror<br/><a href="'.$loginLink.'">"'.$loginLink.'"</a><br/><br/><br/>Sincerely,<br/>
									Emirror team';
							global $serverAddress;
							sendMail($r2['email_id'],$Subject,$Message,$_SESSION["sess_email"]);
							
						}
					}
				}
			$this->_redirect("/album/index/all");	
		}
			
	}
	function downloadFileAction()
	{
				
							/*
			|-----------------
			| Chip Error Manipulation
			|------------------
			*/

			error_reporting(-1);

			/*
			|-----------------
			| Chip Constant Manipulation
			|------------------
			*/

			//define( "CHIP_DEMO_FSROOT",				__DIR__ . "/" );

			/*
			|-----------------
			| Chip Download Class
			|------------------
			
			*/
			include('../lib/chip_download.php');
			/*
			|-----------------
			| Class Instance
			|------------------
			*/

			$download_path = '../'.$this->CONFIG->path->albumPhotosBig;
			$file=base64_decode($_GET['file']);
				$imagesDir = '../'.$this->CONFIG->path->albumPhotosBig;
				$fullPath=$imagesDir.$file;

			$args = array(
					'download_path'		=>	$download_path,
					'file'				=>	$file,		
					'extension_check'	=>	TRUE,
					'referrer_check'	=>	FALSE,
					'referrer'			=>	NULL,
					);
			$download = new chip_download( $args );

			/*
			|-----------------
			| Pre Download Hook
			|------------------
			*/

			$download_hook = $download->get_download_hook();
			//$download->chip_print($download_hook);
			//exit;

			/*
			|-----------------
			| Download
			|------------------
			*/

			if( $download_hook['download'] == TRUE ) {

				/* You can write your logic before proceeding to download */
				
				/* Let's download file */
				$download->get_download();

			}
			}
	public function saveTagAction()
	{
		if ($_POST['type'] == "insert")
		{
			$getCount = Doctrine::getTable('Tagging')->getTagRec($_POST['photoId'],$_POST['userId']);
			if($getCount == 0)
			$id = Doctrine::getTable('Tagging')->addTag($_POST);
		}

		if ($_POST['type'] == "remove")
		{
		  $tag_id = $_POST['tag_id'];
		  $id = Doctrine::getTable('Tagging')->deleteTag($tag_id);
		}
		$jsonData['output'] = 1;
		$this->_helper->json->sendJson($jsonData);	

	}
	public function tagListAction()
	{	
		$picId = $_POST['pic_id'];
		$result = Doctrine::getTable('Tagging')->getList($picId);
		$display  = '';
		foreach($result as $result)
		{
			$name = Doctrine::getTable('Users')->getName($result['user_id']);
			$display  = $display."<li rel=".$result['id']."><a>".$name."</a> (<a class=remove>Remove</a>)</li>";
		}
		$jsonData['outputtaglist'] = $display;
		$this->_helper->json->sendJson($jsonData);	
	}
	public function tagShowAction()
	{	
		$picId = $_POST['pic_id'];
		$result = Doctrine::getTable('Tagging')->getList($picId);
		$display  = '';
		foreach($result as $result)
		{
			$display  = $display."<div class=tagview style=left:".$result['pic_x']."px;top:".$result['pic_y']."px; id=view_".$result['id']."></div>";
		}
		$jsonData['outputtagshow'] = $display;
		$this->_helper->json->sendJson($jsonData);	
	}
			
	public function autosuggestContactsAction()
	{
		$photoId = $this->_getParam('id')?$this->_getParam('id'):'';		
		$this->_helper->layout->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		$q = '';
		if (isset($_GET['q'])) {
			$q = strtolower($_GET['q']);
		}
		if (!$q) {
			return;
		}
		$items = array();
		$memid=$_SESSION["sess_userid"];
		$a = Doctrine::getTable('Contacts')->getContactsTagging($memid,$photoId);
			//echo '<pre>';print_r($a);exit;
			$jsonData = array();
			if(count($a)>0)
			{
				foreach($a as $key=>$mails)
				{
					$items[$mails['contact_id']] = $mails['first_name'];
				}
			}
		foreach ($items as $key => $value) {
			if (strpos(strtolower($value), $q) !== false) {
				echo "$value@#$key\n";
			}
		}
	
	}
	public function allContactsAction()
	{
		$this->_helper->layout->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		$q = '';
		if (isset($_GET['q'])) {
			$q = strtolower($_GET['q']);
		}
		if (!$q) {
			return;
		}
		$items = array();
		$memid=$_SESSION["sess_userid"];
		$a = Doctrine::getTable('Users')->getContacts($memid);
			//echo '<pre>';print_r($a);exit;
			$jsonData = array();
			if(count($a)>0)
			{
				foreach($a as $key=>$mails)
				{
					$items[$mails['user_id']] = $mails['first_name'];
				}
			}
		foreach ($items as $key => $value) {
			if (strpos(strtolower($value), $q) !== false) {
				echo "$value@#$key\n";
			}
		}
	
	}


}	
	